<template>
  <div>
    <el-date-picker
        :unlink-panels="true"
        size="small"
        v-model="value_date"
        type="datetimerange"
        :picker-options="pickerOptions"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        value-format="yyyy-MM-dd HH:mm:ss"
        align="right">
    </el-date-picker>
    <el-input style="width: 200px; margin: 30px 10px; border-top: 1px solid #dcdfe6;"  placeholder="请输入井号" suffix-icon="el-icon-search"
              size="small" v-model="jh"/>
    <el-button type="primary" size="small" @click="search">搜索</el-button>


    <el-table ref="table" :data="tableData"
              style="margin: 30px 0 10px 10px; width: 1600px" size="small" stripe>
      <el-table-column width="50" type="index">
      </el-table-column>

      <el-table-column prop="username" label="用户" width="60">
      </el-table-column>
<!--      <el-table-column prop="dw" label="单位" width="150">-->
<!--      </el-table-column>-->
      <el-table-column prop="createdate" label="日期" width="150">
      </el-table-column>
      <el-table-column prop="optype" label="操作类型" width="150">
      </el-table-column>
      <el-table-column prop="opcontent" label="相关信息">
      </el-table-column>

      <!--      <el-table-column prop="role.roleName" label="角色" width="200">-->
      <!--      </el-table-column>-->

    </el-table>


    <div class="block" style="padding: 5px">
      <el-pagination
          size="small"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[15, 20, 50, 100,500,1000]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>

  </div>

</template>
<script>
import service from "@/utils/request";
import ElementUI from "element-ui";

import VueRouter from 'vue-router'
import HomeView from "@/views/HomeView.vue";
import {formatDateTime} from "@/utils/formatDateTime";


export default {
  created() {
    this.value_date = [formatDateTime(new Date(new Date().getTime() - 3600 * 1000 * 24 * 1), "yyyy-MM-dd HH:mm:ss"), formatDateTime(new Date(), "yyyy-MM-dd HH:mm:ss")];
    this.load();
  },
  data() {
    return {
      pickerOptions: {
        shortcuts: [
          {
            text: '今天',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 1);
              picker.$emit('pick', [start, end]);
            }
          },
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
      },
      value_date: [],
      jh: '',
      tableData: [],
      selectedRows: [], // 用来存储选中行的数据
      pageSize: 15,
      total: null,
      currentPage: 1,
      formLabelWidth: '120px'
    }
  },


  methods: {
    test() {
      service.get('/dj/test', {}).then(
          response => {
            if (response.data.code == 20000) {

              this.$message.success(response.data.message)
            }
          }
      )

    },

    load() {
      service.get('/log/getpage', {
        params: {
          pageSize: this.pageSize,
          pageNum: this.currentPage,
          start: this.value_date==null || this.value_date[0]==null ?null:this.value_date[0],
          end: this.value_date==null || this.value_date[1]==null ?null:this.value_date[1],
          jh: this.jh,
        }
      }).then(response => {
            if (response.data.code == 20000) {
              this.tableData = response.data.data.records;
              this.total = response.data.data.total;
              this.currentPage = response.data.data.current;
              this.pageSize = response.data.data.size;
            }
          },
          error => {
            ElementUI.Message({
              message: error.message,
              type: 'error'
            })
          }
      );
    },


    handleSizeChange(val) {
      this.pageSize = val
      this.load()
    },

    handleCurrentChange(val) {
      this.currentPage = val
      this.load()
    },

    search() {
      this.load()
    },


  }
}
</script>

<style scoped>

</style>
